package cn.snmp.mutual.util;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.snmp.mutual.data.ObjService;

/**
 * @author dengkn
 */
@Slf4j
public class CheckUtilities {

    public CheckUtilities() {
    }

    public CheckUtilities(int min, int max, ObjService existPortList) {
    }

    public static boolean isBigYear(int year) {
        return year % 400 == 0 || year % 4 == 0 && year % 100 != 0;
    }

    public static boolean isValidAddress(String strAddress, String strMark) {
        int iAddress = Utilities.ipAddressStringToInt(strAddress);
        int iMark = Utilities.ipAddressStringToInt(strMark);
        return (iAddress & ~iMark) == 0;
    }

    public static boolean isIPAddress(String ipAddress) {
        try {
            String[] subIpAddress = Utilities.stringSplit(ipAddress, '.');
            if (subIpAddress.length != 4) {
                return false;
            } else {
                int intIpAddress;
                for (intIpAddress = 0; intIpAddress < 4; ++intIpAddress) {
                    if (!between(0L, subIpAddress[intIpAddress], 255L)) {
                        return false;
                    }
                }
                intIpAddress = Utilities.ipAddressStringToInt(ipAddress);
                if ((intIpAddress & Integer.MIN_VALUE) != 0 && (intIpAddress & -1073741824) != Integer.MIN_VALUE
                        && (intIpAddress & -536870912) != -1073741824 && intIpAddress != 0) {
                    return false;
                } else {
                    return true;
                }
            }
        } catch (Exception arg5) {
            DumpUtil.debug(arg5);
            return false;
        }
    }

    public static boolean isMark(String mark) {
        try {
            String[] e = Utilities.stringSplit(mark, '.');
            if (e.length != 4) {
                return false;
            } else {
                int intMark;
                for (intMark = 0; intMark < 4; ++intMark) {
                    if (!between(0L, e[intMark], 255L)) {
                        return false;
                    }
                }

                intMark = Utilities.ipAddressStringToInt(mark);
                if (intMark == 0) {
                    return false;
                } else {
                    String strBinMarkString = Integer.toBinaryString(intMark);
                    DumpUtil.debug(strBinMarkString);
                    int iPos = strBinMarkString.indexOf("0");
                    if (iPos == -1) {
                        return true;
                    } else {
                        strBinMarkString = strBinMarkString.substring(iPos, strBinMarkString.length());
                        iPos = strBinMarkString.indexOf("1");
                        if (iPos != -1) {
                            return false;
                        } else {
                            return true;
                        }
                    }
                }
            }
        } catch (Exception arg4) {
            DumpUtil.debug(arg4);
            return false;
        }
    }

    public static boolean isMACAddress(String str) {
        if (str.length() != 17) {
            return false;
        } else {
            String[] number = Utilities.stringSplit(str, ':');
            if (number.length != 6) {
                return false;
            } else {
                try {
                    for (int e = 0; e < 6; ++e) {
                        String numStr = "0x" + number[e];
                        byte j = (byte) Integer.decode(numStr).intValue();
                    }
                    return true;
                } catch (Exception e) {
                    log.error("check exception" + e);
                    return false;
                }
            }
        }
    }

    public static boolean between(long x, String y, long z) {
        try {
            int e = Integer.valueOf(y).intValue();
            return between(x, (long) e, z);
        } catch (Exception arg5) {
            return false;
        }
    }

    public static boolean between(long min, long value, long max) {
        return value >= min && value <= max;
    }

    public static boolean lengthBetween(String min, String value, String max) {
        try {
            int e = Integer.valueOf(min).intValue();
            int iMax = Integer.valueOf(max).intValue();
            int length = value.length();
            return between((long) e, (long) length, (long) iMax);
        } catch (Exception arg5) {
            DumpUtil.debug(arg5);
            return false;
        }
    }

    public static boolean between(String min, String value, String max) {
        try {
            long e = Long.valueOf(min).longValue();
            long lMax = Long.valueOf(max).longValue();
            long lntValue = Long.valueOf(value).longValue();
            return between(e, lntValue, lMax);
        } catch (Exception arg8) {
            DumpUtil.debug(arg8);
            return false;
        }
    }

    public static int charCount(String str, char c) {
        if (str != null && str.length() != 0) {
            int count = 0;

            for (int i = 0; i < str.length(); ++i) {
                if (str.charAt(i) == c) {
                    ++count;
                }
            }

            return count;
        } else {
            return 0;
        }
    }

    public static boolean isNumberString(String value) {
        if (value != null && value.length() != 0) {
            for (int i = 0; i < value.length(); ++i) {
                if (!isNumber(value.charAt(i))) {
                    return false;
                }
            }

            return true;
        } else {
            return false;
        }
    }

    public static boolean isNumber(char c) {
        return c >= 48 && c <= 57;
    }
}